'use strict';
const BaseController = require('./base');
const { replyRules, deleteReplyRules } = require('../validator/themeCommentReply');
class themeCommentReply extends BaseController {

  // 新增回复评论
  async reply() {
    const { ctx, service, app } = this;
    const errors = app.validator.validate(replyRules, ctx.request.body);
    errors && ctx.helper.commonErr('参数错误', { beans: errors });
    const user_id = ctx.helper.decodeJwt(ctx);
    const data = ctx.request.body;
    const res = await service.themeCommentReply.reply({
      ...data,
      user_id,
    });
    ctx.helper.success({ bean: res }, '新增回复评论成功！');
  }

  // 删除回复评论
  async deleteReply() {
    const { ctx, service, app } = this;
    const errors = app.validator.validate(deleteReplyRules, ctx.request.body);
    errors && ctx.helper.commonErr('参数错误', { beans: errors });
    const { id } = ctx.request.body;
    const res = await service.themeCommentReply.deleteReply(id, ctx.helper.time());
    ctx.helper.success({ bean: res }, '删除回复评论成功');
  }
}

module.exports = themeCommentReply;
